home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1995 May / PC Answers CD-ROM 7 (Future Publishing) (May 1995).iso / vbits / code / robinson / findxl.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-03-24  |  5.2 KB  |  140 lines

  1. VERSION 2.00
  2. Begin Form frmFindXL 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "FindXL"
  5.    ClientHeight    =   1080
  6.    ClientLeft      =   1080
  7.    ClientTop       =   1485
  8.    ClientWidth     =   3615
  9.    Height          =   1485
  10.    Icon            =   FINDXL.FRX:0000
  11.    Left            =   1020
  12.    LinkTopic       =   "frmGOCO"
  13.    MaxButton       =   0   'False
  14.    ScaleHeight     =   1080
  15.    ScaleWidth      =   3615
  16.    Top             =   1140
  17.    Width           =   3735
  18.    Begin CommandButton cmdAbout 
  19.       Caption         =   "About"
  20.       Height          =   285
  21.       Left            =   2430
  22.       TabIndex        =   3
  23.       Top             =   720
  24.       Width           =   1095
  25.    End
  26.    Begin CommandButton cmdCancel 
  27.       Cancel          =   -1  'True
  28.       Caption         =   "Close"
  29.       Height          =   285
  30.       Left            =   1260
  31.       TabIndex        =   1
  32.       Top             =   720
  33.       Width           =   1095
  34.    End
  35.    Begin CommandButton cmdDoIt 
  36.       Caption         =   "Find"
  37.       Default         =   -1  'True
  38.       Height          =   285
  39.       Left            =   90
  40.       TabIndex        =   0
  41.       Top             =   720
  42.       Width           =   1095
  43.    End
  44.    Begin Label labAbout 
  45.       Caption         =   "FindXL is a debug tool to aid in developing and testing applications using Visual Basic 3.0 and the OLE Automation objects in Microsoft Excel. When Visual Basic 3.0 ends without closing a hidden copy of Microsoft Excel, for example in the event of a run-time error, the hidden copy cannot be found and terminated with Task Manager. Furthermore, you may wish to examine the state of the hidden instance. This applet allows you to do so relatively easily."
  46.       FontBold        =   0   'False
  47.       FontItalic      =   0   'False
  48.       FontName        =   "MS Sans Serif"
  49.       FontSize        =   8.25
  50.       FontStrikethru  =   0   'False
  51.       FontUnderline   =   0   'False
  52.       Height          =   2265
  53.       Left            =   90
  54.       TabIndex        =   4
  55.       Top             =   1080
  56.       Width           =   3435
  57.    End
  58.    Begin Label labInfo 
  59.       Caption         =   "Use OLE Automation to find hidden instances of Microsoft Excel and make them visible."
  60.       FontBold        =   0   'False
  61.       FontItalic      =   0   'False
  62.       FontName        =   "MS Sans Serif"
  63.       FontSize        =   8.25
  64.       FontStrikethru  =   0   'False
  65.       FontUnderline   =   0   'False
  66.       Height          =   555
  67.       Left            =   90
  68.       TabIndex        =   2
  69.       Top             =   90
  70.       Width           =   3435
  71.    End
  72. Option Explicit
  73. Dim miOriginalHeight As Integer
  74. ' MsgBox parameters
  75. Const MB_OK = 0                 ' OK button only
  76. Const MB_YESNO = 4              ' Yes and No buttons
  77. Const MB_ICONQUESTION = 32      ' Warning query
  78. Const MB_ICONEXCLAMATION = 48   ' Warning message
  79. Const MB_ICONINFORMATION = 64   ' Information message
  80. ' MsgBox return values
  81. Const IDOK = 1                  ' OK button pressed
  82. Const IDCANCEL = 2              ' Cancel button pressed
  83. Const IDYES = 6                 ' Yes button pressed
  84. Const IDNO = 7                  ' No button pressed
  85. Sub cmdAbout_Click ()
  86.     If cmdAbout.Caption = "About" Then
  87.         miOriginalHeight = frmFindXL.Height
  88.         frmFindXL.Height = frmFindXL.Height + labAbout.Height
  89.         cmdAbout.Caption = "OK"
  90.         cmdDoIt.Enabled = False
  91.         cmdCancel.Enabled = False
  92.     Else
  93.         frmFindXL.Height = miOriginalHeight
  94.         cmdAbout.Caption = "About"
  95.         cmdDoIt.Enabled = True
  96.         cmdCancel.Enabled = True
  97.     End If
  98. End Sub
  99. Sub cmdCancel_Click ()
  100.     Unload Me
  101. End Sub
  102. Sub cmdDoIt_Click ()
  103.     Dim objXL As object
  104.     Dim strMsg As String
  105.     ' Set error handling for GetObject call.
  106.     '
  107.     On Error GoTo NoExcel
  108.     ' First, call GetObject() with no filename, and the ID of the
  109.     ' Microsoft Excel Application object. If there are instances
  110.     ' currently running, this returns the Application object
  111.     ' of the most recently loaded instance.
  112.     '
  113.     Set objXL = GetObject(, "Excel.Application")
  114.     ' Any errors from this point on just get displayed.
  115.     '
  116.     On Error GoTo BadOLE
  117.     If objXL.visible = True Then
  118.         strMsg = "An instance of Microsoft Excel was found, but "
  119.         strMsg = strMsg & "it is already visible. If there are hidden "
  120.         strMsg = strMsg & "instances, they were started before the visible "
  121.         strMsg = strMsg & "instance. In order to find them, the visible "
  122.         strMsg = strMsg & "instance must first be closed."
  123.         MsgBox strMsg, MB_ICONINFORMATION, "FindXL"
  124.     Else
  125.         strMsg = "A hidden instance of Microsoft Excel was found. "
  126.         strMsg = strMsg & "Do you want to make it visible?"
  127.         If MsgBox(strMsg, MB_ICONQUESTION Or MB_YESNO, "FindXL") = IDYES Then
  128.             objXL.visible = True
  129.         End If
  130.     End If
  131.     Exit Sub
  132. NoExcel:
  133.     strMsg = "No application instances of Microsoft Excel were found."
  134.     MsgBox strMsg, MB_ICONINFORMATION, "FindXL"
  135.     Exit Sub
  136. BadOLE:
  137.     MsgBox Error, MB_ICONEXCLAMATION, "FindXL"
  138.     Exit Sub
  139. End Sub
  140.